Skip to content

TST: Testing for mixed int/str Index #61349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 71 commits into
base: main
Choose a base branch
from
Open

Conversation

xaris96
Copy link

@xaris96 xaris96 commented Apr 24, 2025

pelagiavlas and others added 26 commits March 26, 2025 22:58
@datapythonista
Copy link
Member

@xaris96 Can you fix the broken tests and remove all your debug files from this PR please?

@datapythonista datapythonista added Testing pandas testing functions or related to the test suite Index Related to the Index class or subclasses labels May 3, 2025
@datapythonista datapythonista changed the title Issue tm TST: Testing for mixed int/str Index May 3, 2025
@xaris96 xaris96 requested a review from mroeschke May 14, 2025 13:47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should have not been changed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should have not been changed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not have changed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I’m aware — as I mentioned earlier, I ran into an unexpected issue with the test_rolling.py file. It had been working fine before and I hadn’t modified it, so I’m not sure why it started failing. Please let me know if it is a common failure or if there is any other solution for this.

@xaris96 xaris96 requested a review from mroeschke May 15, 2025 11:31
xaris96 and others added 6 commits May 22, 2025 19:30
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
@xaris96 xaris96 requested a review from mroeschke May 23, 2025 07:30
mark = pytest.mark.xfail(reason="complex objects are not comparable")
request.applymarker(mark)
request.applymarker(pytest.mark.xfail(reason="GH 14833", strict=False))
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove all these returns? We want to apply the mark and then let the test run as normal

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the diff and consistently use these following conventions

  1. Use inferred_type to check for the new mixed-int-string case you added
  2. If a test fails, do not astype or pytest.skip. Add an pytest.mark.xfail to the test instead

Comment on lines +629 to +631
# special case for mixed types
if index.inferred_type == "mixed":
index = index.map(str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an xfail marker here instead?

Comment on lines +443 to +444
if len({type(x) for x in index_with_missing if pd.notna(x)}) > 1:
index_with_missing = index_with_missing.map(str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check .inferred_type and xfail if needed.

Comment on lines +456 to +458
non_na_values = [x for x in index_with_missing if pd.notna(x)]
if len({type(x) for x in non_na_values}) > 1:
index_with_missing = index_with_missing.map(str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check .inferred_type and xfail if needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this file? These tests are exercised across the test suite

Comment on lines +158 to +160
has_str = any(isinstance(x, str) for x in index)
has_int = any(isinstance(x, int) for x in index)
if has_str and has_int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check .inferred_type.

Comment on lines +66 to +69
@pytest.mark.parametrize(
"index_or_series_obj", [[1, 2, 3], ["a", "b", "c"], [0, "a", 1, "b", 2, "c"]]
)
@pytest.mark.parametrize("sort", [True, False])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@pytest.mark.parametrize(
"index_or_series_obj", [[1, 2, 3], ["a", "b", "c"], [0, "a", 1, "b", 2, "c"]]
)
@pytest.mark.parametrize("sort", [True, False])

This overrides the original fixtures being used here


for idx in [index1, index2]:
for lvl in range(idx.nlevels):
if has_mixed_types(idx.get_level_values(lvl)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check inferred_type

Comment on lines +939 to +941
pytest.skip(
f"Mixed types in MultiIndex level {lvl} are not orderable"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an xfail marker instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Index Related to the Index class or subclasses Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TST: mixed_int_string Index
5 participants